package cn.jsu.oj.dispatchServer.satellite.util;

import com.alibaba.fastjson.JSON;

import java.io.*;

/**
 * 文件工具
 *
 * @author shan
 * @date 2022/07/05
 */
public class FileUtil {

    /**
     * 文件读取
     *
     * @param path 路径
     * @return {@link byte[] }
     */
    public static byte[] fileReader(String path) {
        File file = new File(path);
        byte[] bytes = new byte[0];
        try {
            FileInputStream fileInputStream = new FileInputStream(file);

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int length;
            while ((length = fileInputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, length);
            }
            bytes = outputStream.toByteArray();
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bytes;
    }
    
    public static String[] dirReader(String path) {
        File file = new File(path);
        if (file.isDirectory()) {
            return file.list();
        }
        return null;
    }
}
